import React, { Component } from "react";

export default class Header extends Component {
  state = { todoVal: "" };

  addTodo = () => {
    const todoItem = {
      id: new Date().getTime(),
      content: this.state.todoVal,
      complete: false,
    };
    this.props.setTodoList(todoItem);
  };

  setVal = (dataType) => {
    return (event) => {
      this.setState({
        [dataType]: event.target.value,
      });
    };
  };

  render() {
    return (
      <div>
        <input
          type="text"
          value={this.state.val}
          onChange={this.setVal("todoVal")}
        />
        <button onClick={this.addTodo}>确定</button>
      </div>
    );
  }
}
